﻿@model IEnumerable<QBWeb.Models.TestFolder.TestPaperTb>
@{
    ViewBag.Title = "_Card1";
    Layout = null;
}

<style>
    .row{
        margin-left:0;
        margin-right:0;
    }
    hr{
        margin-top:10px;
        margin-bottom:10px;
    }
</style>

<div class="row" style="margin:0 10px 10px 10px;">
    <div class="col-md-12">
        <div class="row">
            <div class="col-md-2">
            </div>
            <div class="col-md-8">

            </div>
            <div class="col-md-2">
                <button class="layui-btn layui-btn-normal pull-right" id="createTest"><span class="glyphicon glyphicon-plus"></span>&nbsp;创建试卷</button>
            </div>
        </div>

    </div>
</div>
<div class="row">
    <div class="col-md-12">
        <div class="panel panel-default">
            <div class="row" id="title">
                <div class="col-md-2 col-sm-2"><span>试卷名称</span></div>
                <div class="col-md-2 col-sm-2"><span>作者</span></div>
                <div class="col-md-2 col-sm-2"><span>创建时间</span></div>
                <div class="col-md-2 col-sm-2"><span>修改试卷</span></div>
                <div class="col-md-4 col-sm-4"></div>
                <hr />
            </div>
            <div id="table_body">

            </div>
        </div>
        <div id="demo1"></div>
    </div>
</div>

<script src="~/Scripts/DateTime.js"></script>
<script src="~/Scripts/TestPaper/TestFunction.js"></script>
<script>
    $(document).ready(function () {
        var test;
        var str = window.location.search;
        var index = str.indexOf('=');
        var cid = str.substring(index + 1);
        getTest();

        // 获取试卷
        function getTest() {
            $.ajax({
                async: false,
                url: '/TestPaperTbs/ResultAllTest',
                type: 'get',
                data: {
                    curriculaId: cid
                },
                dataType: 'json',
                //timeout: 5000,
                success: function (json) {
                    test = json;

                    layui.use(['laypage', 'layer'], function () {
                        var laypage = layui.laypage, layer = layui.layer;
                        laypage.render({
                            elem: 'demo1'
                            , count: test.length
                            , jump: function (obj) {
                                document.getElementById('table_body').innerHTML = function () {
                                    var arr = [], thisData = test.concat().splice(obj.curr * obj.limit - obj.limit, obj.limit);
                                    layui.each(thisData, function (index, item) {
                                        var items = showTest(index);
                                        arr.push(items);
                                    });
                                    return arr.join('');
                                }();
                            }
                        });
                    });
                },
            });
        };
        function showTest(id) {
            var str = '';
            const testId = test[id].testId;

            if ("@User.IsInRole("teachers")" === "True" || "@User.IsInRole("admin")" === "True") {
                if (test[id].status === 0) {
                    str = `<button type="button" class="layui-btn layui-btn-sm issue" button-Item="${testId}">发布 </button>
                            <button type="button" class="layui-btn layui-btn-normal layui-btn-sm updateTest" button-Item="${testId}">进入</button>
                            <button type="button" class="layui-btn layui-btn-warm layui-btn-sm editTest" button-Item="${testId}">编辑</button>
                            <button type="button" class="layui-btn layui-btn-danger layui-btn-sm deleteTest" button-Item="${testId}">删除</button>`;
                } else if (test[id].status === 1) {
                    str = `<button type="button" class="layui-btn layui-btn-normal layui-btn-sm answerIs" button-Item="${testId}">查看答题情况</button>
                            <button type="button" class="layui-btn layui-btn-danger layui-btn-sm shutdownIssue" button-Item="${testId}">结束发布</button>`;
                } else if (test[id].status === 3) {
                    str = `<button type="button" class ="layui-btn layui-btn-normal layui-btn-sm examInfo" button-Item="${testId}">考试详细信息</button>
                            <a href="/AnswerInfoTb/TeacherReviewPaper/${testId}" style="text-decoration:none" class="layui-btn layui-btn-primary layui-btn-sm" >批阅试卷</a>
                            <button type="button" class="layui-btn layui-btn-danger layui-btn-sm deleteTest" button-Item="${testId}">删除</button>`;
                }
            } else {
                layer.msg("您还未登录，请登录后进行操作");
            }
            const items = `<div class="row">
                            <div class="col-md-2 col-sm-2"><span id="TestName_${testId}">${test[id].testName}</span></div>
                            <div class="col-md-2 col-sm-2"><span id="Creator_${testId}">${test[id].author}</span></div>
                            <div class="col-md-2 col-sm-2"><span id="CreateTime_${testId}">${test[id].createTime}</span></div>
                            <div class="col-md-2 col-sm-2"><span id="ModifyTime_${testId}">${test[id].modifyTime}</span></div>
                            <div class="col-md-4 col-sm-4" style="margin-bottom:10px;">${str}</div>
                            <hr/>
                           </div>`;
            return items;
        }


    });
</script>
<script>

    $("div").on("click", ".chooses", function () {
        var arr = [];

        var n = $("#cvsk").val();
        if (n != "") {
            arr.push(n);
        };

        var item = $(".chooses");

        //var item_id = $("input[id][name$='ID']");
        for (var i = 0; i < item.length; i++) {
            if (item[i].checked) {
                var item_id = $(item[i]).parent().find("#item_Id").val();
                for (var p = 0; p < arr.length; p++) {
                    if (arr[p] == $(item_id).val()) {
                        //alert("该题目已存在");
                        // return false;
                    }
                    arr.push(item_id);
                }
            }
        }
        $("#cvsk").val(arr);
        //$(".chooses").off("click");
        //return false;
    });

    var testDetails = $("#TestDetailsTbId").val();
    $("div").on("click", "#add2",
        function () {
            $.post("/Main/Yunyong",
                {
                    testDetailsId: testDetails
                });
        });

</script>